package com.hbdl.web.sys.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hbdl.common.spring.annotation.Log;
import com.hbdl.common.spring.annotation.LogType;
import com.hbdl.web.sys.service.SysUserService;

/**
 * 登录控制器
 * @author ql
 *
 */
@SuppressWarnings("rawtypes")
@Controller
@RequestMapping("/")
public class LoginController {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Resource
	private SysUserService sysUserService;	

	/**
	 * 跳转到登录页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "login", method = RequestMethod.GET)
	public String toLogin() {
//		if( SysUserUtils.getSessionLoginUser() != null && SysUserUtils.getCacheLoginUser() !=null ){
//			return "redirect:/";
//		}
		logger.debug("未登录，登录界面跳转");
		return "login";
	}
	
	@Log(type = LogType.LOGIN, description = "用户登录", entityType = "")
	@RequestMapping(value = "login", method = RequestMethod.POST)
    public String login(Model model, HttpServletRequest request) {

//		return "index";
		return "redirect:/index";
    }
	
	/**
	 * 用户退出
	 * 
	 * @return 跳转到登录页面
	 */
	@RequestMapping("logout")
	public String logout(HttpServletRequest request) {
//		SysUserUtils.clearCacheUser(SysUserUtils.getSessionLoginUser().getId());
		request.getSession().invalidate();
		logger.debug("退出");
		return "redirect:/login";
	}
	
	
}
